﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;

namespace Client
{
    public partial class FrmOrderManager : BaseChildForm
    {
        public static FrmOrderManager frm=null;
        public FrmOrderManager()
        {
            InitializeComponent();
            frm = this;
        }

        private void FrmOrderManager_Load(object sender, EventArgs e)
        {
            QueryData(true);
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            QueryData(false);
        }

        public void QueryData(bool init)
        {
            QunYing.BLL.OrderInfo orderInfo = new QunYing.BLL.OrderInfo();
            DateTime? startDate = null;
            DateTime? endDate = null;
            if (this.dateSpanOrder.StartDateEdit.EditValue != null)
            {
                startDate = Convert.ToDateTime(this.dateSpanOrder.StartDateEdit.EditValue);
            }
            if (this.dateSpanOrder.EndDateEdit.EditValue != null)
            {
                endDate = Convert.ToDateTime(this.dateSpanOrder.EndDateEdit.EditValue).AddHours(23).AddSeconds(59).AddMinutes(59);
            }
            sharpGrid1.DataSource = orderInfo.GetOrderList(GlobalInfo.UserLoginInfo.用户ID, txtOrderNo.Text.Trim(), startDate,
                                                           endDate, cbxState.Text.Trim(), init);
            GridView view = this.sharpGrid1.MainView as GridView;
            view.Columns[2].DisplayFormat.FormatType = FormatType.DateTime;
            view.Columns[2].DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
            view.Columns[12].DisplayFormat.FormatType = FormatType.DateTime;
            view.Columns[12].DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
            view.Columns[0].Visible = false;
            view.Columns[11].Visible = false;
        }

        private void sharpGrid1_RowDoubleClickEvent(object sender, Spore.Controls.RowDoubleClickEventArg e)
        {
            GridView view = this.sharpGrid1.MainView as GridView;
            int[] selectedRows = view.GetSelectedRows();
            foreach (var v in selectedRows)
            {
                if (v >= 0)
                {
                    object obj = view.GetRow(v);
                    DataRowView row = obj as DataRowView;
                    if (row == null)
                    {continue;}
                    FrmOrderDetail frm = SingleObjManager.GetSingleObj<FrmOrderDetail>();
                    frm.id=Convert.ToInt32(row["订单ID"]);
                    frm.ShowDialog();
                    break;
                }
            }
        }
        public override void BindData()
        {
            QueryData(false);
        }
    }
}